package com.wds.controller;

import com.wds.domain.JsonResult;
import com.wds.exception.CustomException;
import com.wds.mapper.ArticleMapper;
import com.wds.service.ArticleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author WDs , wds8.24@outlook.com
 * @version 1.0
 * @since 2022-10-21 15:43
 */
@RestController
@RequestMapping("/article")
@Api(tags = "文章接口")
public class ArticleController {

    @Autowired
    private ArticleMapper articleMapper;

    @Autowired
    private ArticleService articleService;
//    @GetMapping("/test")
//    public JsonResult test(){
//        LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>();
//        List<Article> articles = articleMapper.selectList(queryWrapper);
//        return JsonResult.ok(articles);
//    }


    @PutMapping("/updateViewCount/{articleId}")
    public JsonResult<Object> updateViewCount(@PathVariable Long articleId) {
        articleService.updateViewCount(articleId);
        return JsonResult.ok();
    }

    @GetMapping("/hotArticleList")
    public JsonResult<Object> hotArticleList() {
        return articleService.hotArticleList();
    }

    @GetMapping("/articleList")
    public JsonResult<Object> articleList(Integer categoryId, int pageNum, int pageSize) {
        return articleService.articleList(categoryId, pageNum, pageSize);
    }

    @GetMapping("/{id}")
    public JsonResult<Object> getArticleDetail(@PathVariable("id") Long articleId) {
        return articleService.getArticleDetail(articleId);
    }
}
